//
//  TestDemo.m
//  CordovaDemo
//
//  Created by menchao on 2018/6/14.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "TestDemo.h"

@interface TestDemo()
@property (nonatomic,copy) NSString *commandCallbackId;

@end


@implementation TestDemo


-(UIAlertController *)callPhoneWithContent:(NSString *)content handler:(void (^)(void))handelr{
    NSString *tips = @"提示";
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:tips message:content preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
      //  CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"错误了"];
        // [self.commandDelegate sendPluginResult:pluginResult callbackId:self.commandCallbackId];
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"立即呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
          //  CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"成功了"];
            //
           /// [self.commandDelegate sendPluginResult:pluginResult callbackId:self.commandCallbackId];

        });
        
        
      
    }]];
    return alert;
}


- (void)testMethodExtuceTime:(void(^)(void))block{
    
    
}


#define kStartTimeSign   CFTimeInterval startTime = CACurrentMediaTime()*1000



#define kEndTimeSign    CFTimeInterval elapsedTime = CACurrentMediaTime()*1000 - startTime \
                         NSLog(@"mthod exctued time :%.2f ms", elapsedTime);



- (void)showAlertDemo:(CDVInvokedUrlCommand*)command{
    NSLog(@"showAlertDemo....");
    
    CFTimeInterval startTime = CACurrentMediaTime()*1000 ;
    
        dispatch_async(dispatch_get_main_queue(), ^{
      
            
        
    });
    UIAlertController *alert =  [self callPhoneWithContent:@"1333" handler:^{
        
    }];
    [self.viewController presentViewController:alert animated:YES completion:nil];
    
    self.commandCallbackId = command.callbackId;

    //

    
    CFTimeInterval elapsedTime = CACurrentMediaTime()*1000 - startTime;
      NSLog(@"mthod exctued time :%.2f ms", elapsedTime);
    if (elapsedTime > 10) {

      
    }
    
}


- (void)testCallBackResult:(CDVInvokedUrlCommand*)command
{
//    NSDictionary* deviceProperties = [self deviceProperties];
//    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
//    
//    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}



@end
